/*
 *                                                     __----~~~~~~~~~~~------___
 *                                    .  .   ~~//====......          __--~ ~~
 *                    -.            \_|//     |||\\  ~~~~~~::::... /~
 *                 ___-==_       _-~o~  \/    |||  \\            _/~~-
 *         __---~~~.==~||\=_    -_--~/_-~|-   |\\   \\        _/~
 *     _-~~     .=~    |  \\-_    '-~7  /-   /  ||    \      /
 *   .~       .~       |   \\ -_    /  /-   /   ||      \   /
 *  /  ____  /         |     \\ ~-_/  /|- _/   .||       \ /
 *  |~~    ~~|--~~~~--_ \     ~==-/   | \~--===~~        .\
 *           '         ~-|      /|    |-~\~~       __--~~
 *                       |-~~-_/ |    |   ~\_   _-~            /\
 *                            /  \     \__   \/~                \__
 *                        _--~ _/ | .-~~____--~-/                  ~~==.
 *                       ((->/~   '.|||' -_|    ~~-/ ,              . _||
 *                                  -_     ~\      ~~---l__i__i__i--~~_/
 *                                  _-~-__   ~)  \--______________--~~
 *                                //.-~~~-~_--~- |-------~~~~~~~~
 *                                       //.-~~~--\
 *                       ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 *
 *                               神兽保佑            永无BUG
 *
 */

package com.neusoft.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.neusoft.dto.ApplyDto;
import com.neusoft.dto.ApproveRetroactiveListDTO;
import com.neusoft.dto.RetroactiveDTO;
import com.neusoft.service.AttendanceService;
import com.neusoft.utils.EmpUtil;
import com.neusoft.utils.ServerResponse;
import com.neusoft.vo.AttendanceVO;
import com.neusoft.vo.RetroactiveVO;
import io.swagger.annotations.Api;
import org.springframework.format.annotation.DateTimeFormat;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.validation.Valid;
import java.util.Date;
import java.util.List;
import java.util.Map;

@RestController
@RequestMapping("/api/attendance")
@Api(tags = "考勤管理", value = "考勤管理API")
public class AttendanceController {
    @Resource
    AttendanceService attendanceService;
    //考勤打卡
    @RequestMapping(value = "/in",method = RequestMethod.POST)
    //type为1上班打卡其余下班打卡
    public ServerResponse<?> attendanceIn(@RequestBody Map<String, Integer> type) {
        //TODO获取用户id？
        Integer id = EmpUtil.getLoginEmpId();
        System.out.println("id:" + id);
        return attendanceService.attendanceIn(id,type.get("type"));
    }
    //考勤查询
    @RequestMapping(value = "/my-records",method = RequestMethod.GET)
    public ServerResponse<List<AttendanceVO>> getMyRecords(@RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date startDate,
                                                           @RequestParam @DateTimeFormat(pattern = "yyyy-MM-dd") Date endDate) {
        //TODO获取用户id？
        Integer id = EmpUtil.getLoginEmpId();
        System.out.println("id:" + id);
        return ServerResponse.success(attendanceService.getMyRecords(id,startDate,endDate));
    }
    //申请考勤补签
    @RequestMapping(value = "/retroactive",method = RequestMethod.POST)
    public ServerResponse<?> applyRetroactive(@RequestBody RetroactiveDTO retroactiveDto) {
        //TODO获取用户id？
        Integer id = EmpUtil.getLoginEmpId();
        System.out.println("id:" + id);
        return attendanceService.applyRetroactive(id,retroactiveDto);
    }
    //考勤补签申请查询
    @RequestMapping(value = "/getRetroactive",method = RequestMethod.GET)
    public ServerResponse<IPage<AttendanceVO>> getMyRetroactiveList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                     @RequestParam(defaultValue = "10") Integer pageSize) {
        return ServerResponse.success(attendanceService.selectRetroactiveList(pageNum,pageSize));
    }
    //审批考勤补签查询
    @RequestMapping(value = "/retroactive",method = RequestMethod.GET)
    public ServerResponse<IPage<RetroactiveVO>> getRetroactiveList(@RequestParam(defaultValue = "1") Integer pageNum,
                                                                   @RequestParam(defaultValue = "10") Integer pageSize) {
        return ServerResponse.success(attendanceService.getRetroactiveList(pageNum,pageSize));
    }
    //审批考勤补签审批
    @RequestMapping(value = "/retroactive/sp-e",method = RequestMethod.PUT)
    public ServerResponse<?> approveRetroactive(@RequestBody ApplyDto applyDto) {
        return attendanceService.approveRetroactive(applyDto.getId(),applyDto.getStatus(),applyDto.getReason());
    }
    //批量审批考勤补签
    @RequestMapping(value = "/retroactive/se",method = RequestMethod.PUT)
    public ServerResponse<?> approveRetroactiveList(ApproveRetroactiveListDTO approveRetroactiveListDTO) {
        return attendanceService.approveRetroactiveList(approveRetroactiveListDTO);
    }

}
